package com.itheima.admin.controller;


import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.enums.HttpCodeEnum;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.core.controller.AbstractCoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;


/**
 * @description <p>频道信息</p>
 *
 * @version 1.0
 * @package com.itheima.admin.controller
 */

@Api(value="AdChannelController",tags = "频道管理")
@RestController
@RequestMapping("/channel")
public class AdChannelController extends AbstractCoreController {

    @Autowired
    private AdChannelService adChannelService;

    public AdChannelController(AdChannelService adChannelService) {
        super(adChannelService);
    }

    /**
     * 查询分页数据和按名字模糊查询
     * @param dto
     * @return
     */
    @ApiOperation("频道分页搜索")
    @PostMapping("/list")
    public ResultVo<AdChannel> findPage(@RequestBody ChannelPageRequestDto dto){

        System.out.println("dto======================"+dto);
        PageResultVo<AdChannel>    resultList = adChannelService.findPage(dto);

        System.out.println("resultList========="+resultList);

        return resultList;
    }

    /**
     * 删除数据
     */
    /**
     * 删除记录
     *
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @ApiOperation("通过Id删除")
    public ResultVo deleteById(@PathVariable long id) {
        boolean flag = coreService.removeById(id);
        if (!flag) {
            return ResultVo.error();
        }
        return ResultVo.ok();
    }

}
